package com.jg.controller;

import com.jg.entity.User;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 86130
 * @version 1.0
 * @description: TODO
 * @date 2025/6/12 上午9:02
 */
@RestController
@RequestMapping("/user")
public class UserController {
    //接受单参数
    @RequestMapping("/getOneParam")
    public String getOneParam(@RequestParam("username") String name) {
        System.out.println("name:" + name);
        return "name:" + name;
    }

    //返回单个对象
    @RequestMapping("/getOneObject")
    public User getOneObject() {
        User user = new User();
        user.setName("张三");
        user.setPassword("123456");
        user.setAge("18");
        user.setSex("男");
        user.setAddress("上海");
        return user;
    }

    //接受form提交参数
    @RequestMapping("/getFormParam")
    public String getFormParam(String name, Integer age) {
        System.out.println("name:" + name + " age:" + age);
        return "name:" + name + " age:" + age;
    }

    //接受对象参数
    @RequestMapping("/getObjectParam")
    public String getObjectParam(User user) {
        System.out.println("接受对象参数："+user);
        return "接受对象参数："+user;
    }

    //接受嵌套对象参数
    @RequestMapping("/getNestObjectParam")
    public String getNestObjectParam(User user) {
        System.out.println("接受嵌套对象参数："+user);
        System.out.println("接受嵌套对象参数"+user.getIdCard());
        return "接受嵌套对象参数："+user;
    }

    //接受string数组参数
    @RequestMapping("/getStringArrayParam")
    public String getStringArrayParam(String[] names) {
        System.out.println("接受string数组参数"+names);
        return "接受string数组参数"+names;
    }

    //接受list集合参数
    @RequestMapping("/getListParam")
    public String getListParam(@RequestParam List<String> names) {
        System.out.println("接受list集合参数"+names);
        return "接受list集合参数"+names;
    }

    //接受json参数  普通数组
    @RequestMapping("/getJsonArrayParam")
    public String getJsonArrayParam(@RequestBody String[] names) {
        System.out.println("接受json参数普通数组"+names);
        return "接受json参数普通数组"+names;
    }

    //接受json参数  list集合
    @RequestMapping("/getJsonListParam")
    public String getJsonListParam(@RequestBody List<String> names) {
        System.out.println("接受json参数list集合"+names);
        return "接受json参数list集合"+names;
    }

    //接受json参数  对象
    @RequestMapping("/getJsonObjectParam")
    public String getJsonObjectParam(@RequestBody User user) {
        System.out.println("接受json参数对象"+user);
        return "接受json参数对象"+user;
    }
}
